<script setup>
import { toRef } from 'vue'
import { Plus, Delete } from '@element-plus/icons-vue'
import { infoType, xxmpTemplate } from '@/assets/const'

const props = defineProps(['modelValue'])
const modelValue = toRef(props, 'modelValue')

function deleteWorkByIndex(index) {
  modelValue.value.splice(index, 1)
}
function addMoreRow() {
  modelValue.value.push(xxmpTemplate())
}
</script>
<template>
  <div class="work-list">
    <div class="work-list-row" v-for="(row, index) in modelValue" :key="index">
      <div class="work-list-row-icon">{{ index + 1 }}</div>
      <div class="work-list-row-line"></div>
      <div class="work-list-row-ipt">
        <el-form label-width="auto">
          <el-form-item label="信息类型">
            <el-radio-group v-model="row.infoType">
              <el-radio v-for="(item, key) in infoType" :value="item" :label="item" :key="key" />
            </el-radio-group>
          </el-form-item>
          <el-form-item label="工作内容">
            <el-input v-model="row.content" type="textarea" autosize />
          </el-form-item>
        </el-form>
      </div>
      <div class="work-list-row-line"></div>
      <el-popconfirm
        title="将永久删除"
        confirm-button-text="我确定"
        hide-icon
        @confirm="deleteWorkByIndex(index)"
      >
        <template #reference>
          <el-button type="danger" :icon="Delete" circle size="default" />
        </template>
      </el-popconfirm>
    </div>
    <br />
    <el-button :icon="Plus" style="width: 100%" type="primary" size="large" @click="addMoreRow"
      >再加一条</el-button
    >
  </div>
</template>
<style scoped lang="less"></style>
